package forward.Module.Modules.Misc;

import forward.api.EventHandler;
import forward.api.Events.World.EventPreUpdate;
import forward.Module.Module;
import forward.Module.ModuleType;
import java.awt.Color;
import net.minecraft.client.Minecraft;
import net.minecraft.item.ItemBow;
import net.minecraft.item.ItemFood;
import net.minecraft.item.ItemPotion;
import net.minecraft.item.ItemSword;
import net.minecraft.network.play.client.C03PacketPlayer;
import net.minecraft.network.play.client.C07PacketPlayerDigging;
import net.minecraft.util.BlockPos;
import net.minecraft.util.EnumFacing;

public class FastUse extends Module {

	public FastUse() {
		super("FastUse", new String[] { "fasteat", "fuse" }, ModuleType.Misc);
	}

	private boolean canConsume() {
		if (!(this.mc.thePlayer.getCurrentEquippedItem() != null
				&& this.mc.thePlayer.getCurrentEquippedItem().getItem() instanceof ItemPotion
				|| this.mc.thePlayer.getCurrentEquippedItem().getItem() instanceof ItemFood)) {
			return false;
		}
		return true;
	}

	@EventHandler
	private void onUpdate(EventPreUpdate e) {
		this.setColor(new Color(100, 200, 200).getRGB());
		if (this.mc.thePlayer.onGround && this.mc.thePlayer.getItemInUseDuration() == 16
				&& Minecraft.getMinecraft().gameSettings.keyBindUseItem.pressed
				&& !(this.mc.thePlayer.getItemInUse().getItem() instanceof ItemBow)
				&& !(this.mc.thePlayer.getItemInUse().getItem() instanceof ItemSword)) {
			int i = 0;
			while (i < 17) {
				this.mc.thePlayer.sendQueue.addToSendQueue(new C03PacketPlayer.C05PacketPlayerLook(
						this.mc.thePlayer.rotationYaw, this.mc.thePlayer.rotationPitch, this.mc.thePlayer.onGround));
				++i;
			}
			this.mc.thePlayer.sendQueue.addToSendQueue(new C07PacketPlayerDigging(
					C07PacketPlayerDigging.Action.RELEASE_USE_ITEM, BlockPos.ORIGIN, EnumFacing.DOWN));
		}
	}
}
